home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mem / Documentation / Plain Text / MPW Helpers < prev    next >
Encoding:
Text File  |  1993-08-17  |  12.7 KB  |  323 lines  |  [TEXT/MPS ]

  1.              Icon Programs and Procedures
  2.                          for
  3.             Macintosh Programmer's Workshop
  4.  
  5.                   Robert J. Alexander
  6.  
  7.                        IPD229
  8.                    August 17, 1993
  9.  
  10.  
  11.  
  12.  
  13. The distribution disk for MPW Icon Version 8.10 contains a mini-library of 
  14. programs, procedures, and MPW scripts that serve a dual purpose:  (1) they are 
  15. examples of Icon code, and (2) they are useful MPW utilities.  Building the 
  16. tools and experimenting with them will help to provide insight into the 
  17. capabilities of MPW Icon and a feel for using Icon in the MPW environment.
  18.  
  19. These files are provided on an as-is basis, with no formal support provided as 
  20. such.  They are, however, reasonably error-free — we would like to hear about 
  21. any suggestions or bugs.
  22.  
  23. The files in the MPW Helpers folder are of the following types:
  24.  
  25. •    MPW tools written in Icon
  26. •    MPW Shell scripts to construct custom menu items that increase the 
  27.     utility of the Icon tools
  28. •    Icon procedures you can use in your own tools
  29.  
  30. The files contain sufficient documentation to use them.  This document 
  31. provides an overview explaining how the parts fit together.  Some of the tools 
  32. described in this document are now part of the Icon Program Library, a 
  33. sizeable collection of programs and procedures written in Icon .  The Library 
  34. is available from the Icon Project, University of Arizona.
  35.  
  36.  
  37. The Tools
  38.  
  39. The tools provided are
  40.  
  41.     colm.icn    a tool that formats lines of standard input into 
  42.             columns to be displayed in a window or printed.
  43.     FixIncludes.icn    a tool that changes the filename formats int #include 
  44.             directive from UNIX to Mac format.
  45.     FixMake.icn    a tool that assists in converting a UNIX Makefile to 
  46.             MPW Make format.
  47.     format.icn    a tool that “word wraps” input text to conform to 
  48.             given specifications.  It also formats program 
  49.             comments, preserving any required comment sequence a 
  50.             the start of each line.
  51.     icom.icn    a tool that “comments-out” or “uncomments-in” a 
  52.             section of Icon code — for use with the Encomment and 
  53.             Decomment menu items for operating on Icon programs 
  54.             in MPW windows.
  55.     localx.icn    a utility to report undeclared local identifiers in 
  56.             Icon programs (used in conjunctions with the locals 
  57.             script).
  58.     IconProg.icn    a filter that turns an Icon program fragment or whole 
  59.             program into input suitable for translation by icont 
  60.             (specifically for use in conjunction with one of the 
  61.             supplied script: DoIcon).
  62.     macsf.icn    a tool that creates an aesthetically pleasing list of 
  63.             filenmes separated by suffix.
  64.     SegAlloc.icn    a tool that generates linker commands to allocate 
  65.             program modules to segments so that no segment 
  66.             exceeds the maximum for a segment.
  67.  
  68. The tools are documented in their source files, and can be used as MPW 
  69. commands.  They are put to use in the scripts and menus that are described 
  70. below.  Note that these tools are not limited to the Macintosh environment — 
  71. the author has found them useful in MS-DOS and UNIX environments (especially 
  72. format in conjunction with vi or emacs for formatting program comments).
  73.  
  74.  
  75. The MPW Shell Menus
  76.  
  77. The UserStartup scripts create custom menu items for your MPW environment.  
  78. They are
  79.  
  80.     Do Icon
  81.     Write Empty Procedure
  82.     List Undeclated
  83.     Show ucode
  84.     Mark Icon Procedures
  85.     Encomment
  86.     Decomment
  87.     Output Option...
  88.     Trace Option...
  89.  
  90. These files are intended to be incorporated into the startup scenario of MPW.  
  91. With MPW 3.0, all that is necessary to put them into service is to copy the 
  92. files into your MPW folder.  They will automatically be executed when MPW 
  93. starts up.  With older versions of MPW, you will have to explicitly execute 
  94. them by inserting explicit Execute commands into your UserStartup file.
  95.  
  96. Each of the script files allows you to specify which menu its items will 
  97. appear under.  They can be either under an existing menu, or a new menu name 
  98. can be specified.  The menu name is specified within the script text, and is 
  99. changed by editing the script.
  100.  
  101.  
  102. Icon Menu Items
  103.  
  104. UserStartup•IconMenu creates four menu items specifically for use with the 
  105. Icon Programming Language.  They are
  106.  
  107.     UserStartup•IconMenu
  108.     UserStartup•Format
  109.  
  110. Do Icon allows an Icon program or sequence of expressions to be executed 
  111. directly from any MPW window, usually the Worksheet.  It is useful for quickly 
  112. executing small Icon segments, often just to experimentally determine what 
  113. Icon will do in certain circumstances.  Simply select the text of an Icon 
  114. program that has been typed into a window and choose the Do Icon menu item or, 
  115. more expediently, hit command-I.  (Like the MPW Shell Enter key, if no text is 
  116. selected the whole line will be evaluated).  There is no way to pass command-
  117. line arguments to such a program.
  118.  
  119. Write Empty Procedure creates an Icon program template in the active MPW 
  120. window, usually used quickly creating a program structure for the Do icon menu 
  121. item:
  122.  
  123.     procedure main()
  124.        |
  125.     end
  126.  
  127. The | indicates that the insertion point is positioned for immediate text 
  128. entry after choosing Write Empty Procedure.
  129.  
  130. List Undeclared creates a local declaration for each undeclared local 
  131. identifier in an Icon procedure or program.  To use it, select an entire Icon 
  132. procedure in an MPW window and choose the List Undeclared menu item.  The 
  133. local line will appear below the selected code.  Cut and paste the local line 
  134. into the procedure body.  The List Undeclared utility is unaware of globals 
  135. you have declared, and might include them in the local declaration.  This will 
  136. probably cause your program to malfunction — you must manually remove global 
  137. variable names that accidentally appear in the created local declaration.
  138.  
  139. Show ucode works similarly to Do Icon it that it operates on text in a MPW 
  140. window.  Instead of executing an Icon program, Show ucode displays its ucode 
  141. file.  An often overlooked fact is that the unlinked “object” files output by 
  142. the Icon translator (icont) are human-readable text files that resemble 
  143. assembly language source files.  The target machine for ucode files is the 
  144. Icon virtual machine, emulated by the Icon interpreter iconx.  Often it is 
  145. interesting to see the ucode that is generated by various Icon source code 
  146. constructs.  Show ucode provides a convenient mechanism to view generated 
  147. ucode.  Note that since ucode files are text files, the MPW Shell editor can 
  148. also be used to view ucode files.
  149.  
  150. Mark Icon Procedures creates MPW Shell marks for every procedure and record 
  151. declared in the Icon program file in the active MPW window.  MPW marks allow 
  152. you to move quickly to any procedure or record definition by choosing its name 
  153. from the MPW Shell’s Mark menu.  Additionally, marks are created for all 
  154. global and link declaration lines, so the Mark menu will contain a complete 
  155. index of your Icon program.  If your program composed of multiple files, this 
  156. facility in conjunction with the Mark Browser make it easy to navigate large 
  157. programs.
  158.  
  159. Encomment and Decomment menu items comment out or decomment in the selected 
  160. range of Icon program lines in an MPW editor window.
  161.  
  162. Output Option... presents a dialog box (a list box, really) to allow you to 
  163. choose between normal window output and fast output.  The default, normal 
  164. output is usually adequate, but if large amounts of output are written to a 
  165. window a significant speedup is obtained by selecting the faster option.  
  166. Nothing is free, though — when the fast option is used output to different 
  167. files (like &output and &errout) which are written to the same window will not 
  168. be ordered strictly chronologically; i.e. they get a bit jumbled.
  169.  
  170. Trace Option... presents a list box to allow you to turn run-time procedure 
  171. tracing on and off.
  172.  
  173.  
  174. Format Menu Items
  175.  
  176. UserStartup•Format creates four menu items for performing word-wrap operations 
  177. on text in MPW windows.
  178.  
  179.     Format Paragraph
  180.     Format Comments
  181.     Justify Paragraph
  182.     Justify Last Line Too
  183.  
  184.  
  185. To use any of the Format menu items, first select the range of text you want 
  186. wrapped, then select the menu item.  The Format items operate on mono-spaced 
  187. fonts only, such as Monaco and Courier (the MPW default font is Monaco).
  188.  
  189. Format Paragraph simply wraps the selected text according to the current word-
  190. wrap parameters (parameters are discussed below).
  191.  
  192. Format Comments will word-wrap a range of program comments, leaving the 
  193. comment characters intact and in the proper place.  Format comments will work 
  194. with comment text that has its “comment indicator” string at the beginning of 
  195. each comment line (such as Icon).
  196.  
  197.     #  This is an
  198.     #  Icon program.
  199.  
  200. will work, as will
  201.  
  202.     //  This is a
  203.     //  C++ program.
  204.  
  205. This will not work
  206.  
  207.     { This is a }
  208.     { Pascal program }
  209.  
  210. but this will
  211.  
  212.     /*
  213.      *  This is a
  214.      *  C program
  215.      */
  216.  
  217. as long as only the second and third lines are selected.
  218.  
  219. The comment marker can be preceded by white space.  When selecting comment 
  220. text to wrap, make sure that the first line actually contains comment text, so 
  221. that the format utility can determine the format of text to follow.  For 
  222. example, given
  223.  
  224.     #
  225.     #  getopt() --  The getopt procedure…
  226.  
  227. the text selection should start at the second line, not the first.
  228.  
  229. Another feature of Format Comments is helpful when inserting a large amount of 
  230. new text into a program comment:  it is not necessary to include the “comment 
  231. indicator” string in lines following the first (format establishing) line.  If 
  232. Format Comments is applied to the following text
  233.  
  234.     #  This is a comment string
  235.     containing a whole lot of
  236.     new text and I was too
  237.     lazy to put a # at the
  238.     start of each line
  239.  
  240. it will come out something like this
  241.  
  242.     #  This is a comment string containing a whole lot of new
  243.     #  text and I was too lazy to put a # at the start of each line
  244.  
  245. Justify Paragraph works similarly to Format Paragraph except that the text is 
  246. expanded (by random insertion of space characters) so that it is flush to both 
  247. the left and right margins.  The last line of the justified output is not 
  248. expanded.
  249.  
  250. Justify Last line Too works like Justify Paragraph except that all output is 
  251. expanded including the last line.
  252.  
  253. Note that justified text can be un-justified or re-justified simply by 
  254. applying any of the other word-wrap operations.  Also, the MPW Undo operation 
  255. will unwrap wrapped text if it is performed immediately after the wrap 
  256. operation.
  257.  
  258. Word wrapping parameters (line width, tab settings, and other options) are 
  259. controlled by MPW Shell environment variables.  They are set to default values 
  260. in the UserStartup•Format script.  The defaults can be changed by editing the 
  261. script, or they can be temporarily overridden by resetting the variable 
  262. values.  Refer to the script for details.
  263.  
  264.  
  265. The Scripts
  266.  
  267. lz (el-zee) is a MPW Shell script to provide a command similar to the UNIX ls 
  268. command (directed to a console).  It outputs file names in columnar fashion, 
  269. with file names arranged alphabetically vertically within columns.  It uses 
  270. the colm tool to arrange the columns, and does so in a quite sophisticated 
  271. way.  The width of each column is adjusted individually depending on its 
  272. contents, and the total width is adjusted to the current size of the active 
  273. window.  The output format is superior to the MPW files -m n command.  The 
  274. disadvantage:  speed.
  275.  
  276. The lz command is useful when a large number of files are to be listed, and 
  277. especially if the list is to be printed.  There are few other automated 
  278. methods to fit as many file names, readably formatted, into a smaller space!  
  279. lz also works well if the -r option is used (to list files in all included 
  280. directories) — the directory name headings and the file names of each 
  281. directory are kept separate and are listed in a pleasantly readable, compact 
  282. format.
  283.  
  284. The sf command lists files, separated by filename suffix.  Like lz, the 
  285. listing format is compact.
  286.  
  287. Locals determines the undeclared local identifiers in an Icon procedure.  It 
  288. is used in conjunction with the List Undeclared menu item.
  289.  
  290. The provided script, MarkIcon, is used in conjunction with the Mark Icon 
  291. Procedures menu item.
  292.  
  293.  
  294. The Procedures
  295.  
  296. The procedures contain programmer’s documentation within their text.  They are
  297.  
  298.     options.icn
  299.     shquote.icn
  300.     filename.icn
  301.     colmize.icn
  302.     hex.icn
  303.     isort.icn
  304.     fmacunix.icn
  305.  
  306. The options procedure provides a convenient mechanism for processing command-
  307. line options.
  308.  
  309. The mpwquote procedure (in shquote.icn) properly quotes strings (if necessary) 
  310. that are to be recognized as single words within the MPW command language.  It 
  311. performs the same transformation as does the quote MPW tool.  Since Icon can 
  312. be put to good use in generating text to be executed by the MPW Shell, 
  313. mpwquote often comes in handy.
  314.  
  315. suffix (in filename.icn) breaks a file name into its base part and suffix 
  316. parts and returns the result as a two-member list.  suffix("suffix.icn") 
  317. returns ["suffix","icn"].  suffix("xxx") returns ["xxx",&null], but 
  318. suffix("yyy.") returns ["yyy",""].
  319.  
  320. colmize does most of the work for the utility colm, described in this 
  321. document.  The colmize procedure is useful in a variety of programs — see the 
  322. source file for detailed documentation.
  323.